#include<bits/stdc++.h>

#ifndef DEBUG
#define NDEBUG
#endif

#include<assert.h>

using namespace std;
struct Eage
{    
    /* data */
    int v;
    int u;
    int t;    
    Eage(int v,int u, int t){
        this->v = v;
        this->u = u;
        this->t = t;
    }
    bool operator<(const Eage &e)const{
        return this->t > e.t;
    }
};

priority_queue<Eage> eages;//边集
vector<int> father;//并查集，记录每个节点father

int find_fa(const int &x){
    if(father[x] == x)
        return x;
    return father[x] = find_fa(father[x]);
}

int main(){
    int n,m,root;
    cin >> n >> m >> root;
    father.resize(n,0);
    iota(father.begin(), father.end(), 0);//相当于father[i]=i
    int v,u,t;
    //初始化边集
    for(int i=0;i<m;i++){        
           
        cin >> v >> u >> t;        
        eages.push(Eage(v-1,u-1,t));
    }

    //kruskal算法
    int ans = 0;
    while(!eages.empty()){
        auto e = eages.top();
        eages.pop();
        int ra = find_fa(e.v), rb = find_fa(e.u);
        if(ra != rb){
            ans = e.t;
            father[ra] = rb;//这里很关键，要理解
        }
    }
    cout << ans;
}